<?php
include 'functions.php';
if (!$resdap_mod_features) { header('Refresh: 0; URL=http://resources.scratchr.org/'); die(); }

if (isset($_POST['form_id'])) {
	$id       = $_POST['form_id'];
	$title    = $_POST['form_title'];
	$type     = $_POST['form_type'];
	$category = $_POST['form_category'];
	$comments = $_POST['form_comments'];
	$ext      = $_POST['form_ext'];
	$user     = $_POST['form_user'];
	$hide     = $_POST['form_hide'];
	$downloads     = $_POST['form_downloads'];
	
	
	$q = "UPDATE res_resources SET ".
		 "id='$id', ".
		 "title='$title', ".
		 "type='$type', ".
		 "categpry='$category', ".
		 "comments='$comments', ".
		 "ext='$ext', ".
		 "user='$user', ".
		 "hide='$hide', ".
		 "downloads='$downloads', ".
		 "WHERE id=$id";
	dev_out($q);
	/*
	resdap_connect();
	$result = mysql_query($q);*/
}
echo $html_doctype;
?>
<html>
<head>
<title> Scratch Resources | Edit Resource</title>
<?php
	//no metadata, no search engines on this page
	echo $html_meta_nosearch;
	echo $html_css;
	echo $html_scripts;
?>
</head>

<body>

<div id="maincontainer">
	<?php include 'header.php';?>
	
	<div class="box_fullwidth">
	<h1>Edit Resource</h1>
	<?php
	$disablefields='  id ip date ';
	$id = $_GET['id'];
	$q = "SELECT * FROM res_resources WHERE id=$id";
	resdap_connect();
	$result = mysql_query($q);
	if($row = mysql_fetch_assoc($result)) {
		echo '<form class="defaultform" method="POST" action="/adminedit?id='.$id.'">'."\n\n";
		foreach ($row as $key => $value) {
			echo '<label for="form_'.$key.'">'.$key.'</label>'."\n";
			if ($key=='comments') {
				echo '<textarea cols="25" id="form_'.$key.'" name="form_'.$key.'">'.$value.'</textarea><br><br>'."\n";
			} else {
				echo '<input type="text" length="25" value="'.$value.'" id="form_'.$key.'" name="form_'.$key.'"';
				if (strpos($disablefields, " $key ")) {
					echo ' disabled="true" ';
				}
				echo '></input><br><br>'."\n\n";
			}
		}
		echo '<input type="submit" id="okbutton" value="save"></input>'."\n".
			 "</form>\n\n";
	} else {
		echo 'An error occured: your download is unavailable.';
	}
	resdap_disconnect();
	?>
	
	</div>

<?php include('footer.php'); ?>
</div>
</body>

</html>